﻿using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebAPI_DEMO.Filter
{
    /// <summary>
    /// 授权过滤器
    /// 实现自定义授权    --AuthorizeFilter 过滤器、筛选器
    /// 比如登录、密码验证等...
    /// </summary>
    public class AuthorizeFilter :Attribute, IAuthorizationFilter
    {
        //实现过滤 

        /// <summary>
        /// 请求验证，当前验证部分不要抛出异常，ExceptionFilter不会处理
        /// </summary>
        /// <param name="context"></param>
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            //这里可以做复杂的权限控制操作
            //if (context.HttpContext.User.Identity.Name != "1") //简单的做一个示范
            //{
            // //未通过验证则跳转到无权限提示页
            // RedirectToActionResult content = new RedirectToActionResult("NoAuth", "Exception", null);
            // context.Result = content;
            //
        }
    }
}
